import sys


if __name__ == '__main__':
    in_file = sys.argv[1]

    id_dict = {}
    parent_dict = {}

    for l in open(in_file):
        d = l.strip().split(',')
        if len(d) != 4:
            continue

        c1_name, c2_name, c1_id, c2_id = d

        id_dict[c1_id] = c1_name
        id_dict[c2_id] = c2_name

        parent_dict[c1_id] = '0'
        parent_dict[c2_id] = c1_id

    for c_id, c_name in id_dict.items():
        parent_id = parent_dict[c_id]
        out = '\t'.join([c_id, parent_id, c_name])
        print(out)


